package com.hdl.school.adapter;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.RecyclerView;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hdl.school.bean.BuildingInfo;
import com.hdl.school.bean.PlanTaskSource;
import com.hdl.school.schoolcontroller.R;
import com.hdl.school.utils.TimeUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Admin on 2016/10/22.
 */
public class MediaAdapter extends RecyclerView.Adapter<MediaAdapter.MyViewHolder> {

    private Context context;
    private List<PlanTaskSource> tasks;
    private LayoutInflater inflater;

    public MediaAdapter(Context context, List<PlanTaskSource> tasks) {
        this.context = context;
        this.tasks = tasks;
        inflater = LayoutInflater.from(context);
    }


    public List<PlanTaskSource> getTasks() {
        return tasks;
    }

    public void setTasks(List<PlanTaskSource> tasks) {
        this.tasks = tasks;
    }


    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.layout_task_item, parent, false);
        MyViewHolder viewHolder=new MyViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
         PlanTaskSource planTaskSource=tasks.get(position);
         holder.taskDurView.setText(planTaskSource.getPlayStartTime()+"~"+planTaskSource.getPlayEndTime());
         holder.taskNameView.setText(planTaskSource.getTaskName());

         if(planTaskSource.isInPlaying()){
             holder.taskDurView.setTextColor(Color.parseColor("#00CC00"));
             holder.taskNameView.setTextColor(Color.parseColor("#00CC00"));
         }else{
             holder.taskDurView.setTextColor(Color.parseColor("#ffffff"));
             holder.taskNameView.setTextColor(Color.parseColor("#ffffff"));
         }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return tasks==null?0:tasks.size();
    }

    class  MyViewHolder extends RecyclerView.ViewHolder{
        TextView taskNameView;
        TextView taskDurView;
        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            taskNameView = (TextView) itemView.findViewById(R.id.taskname);
            taskDurView= (TextView) itemView.findViewById(R.id.dur);
        }
    }
}
